package com.stm.web.controller.toolsScrap;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stm.common.annotation.Log;
import com.stm.common.core.controller.BaseController;
import com.stm.common.core.domain.AjaxResult;
import com.stm.common.core.page.TableDataInfo;
import com.stm.common.enums.BusinessType;
import com.stm.framework.util.ShiroUtils;
import com.stm.toolsScrap.domain.KfToolsScrapApply;
import com.stm.toolsScrap.service.KfToolsScrapApplyService;

/**
 * 
 * @Description 报废审核controller
 * @CreateTime 2019年4月8日 下午5:06:09
 * @CreateBy 林龙
 */
@Controller
@RequestMapping("/toolsScrap/scrapReview")
public class ScrapReviewController extends BaseController
{
    private String prefix = "toolsScrap/scrapReview";

    @Autowired
    private KfToolsScrapApplyService kfToolsScrapApplyService;

    /**
     * 
     * @Description 跳转页面
     * @CreateTime 2019年4月4日 上午11:57:34
     * @CreateBy 林龙
     * @return
     */
    @RequiresPermissions("toolsScrap:scrapReview:view")
    @GetMapping()
    public String scrapReview(ModelMap mmap)
    {
    	mmap.put("user", ShiroUtils.getSysUser());
        return prefix + "/scrapReview";
    }
    
    /**
     * 
     * @Description 分页查询
     * @CreateTime 2019年4月4日 上午11:57:25
     * @CreateBy 林龙
     * @param kfToolsScrapApply
     * @return
     */
    @RequiresPermissions("toolsScrap:scrapTreatment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KfToolsScrapApply kfToolsScrapApply)
    {
        startPage();
        List<KfToolsScrapApply> list = kfToolsScrapApplyService.selectAllPageList(kfToolsScrapApply);
        return getDataTable(list);
    }
    /**
     * 
     * @Description 审核
     * @CreateTime 2019年4月4日 上午11:56:27
     * @CreateBy 林龙
     * @param ids
     * @return
     */
    @RequiresPermissions("toolsScrap:scrapReview:review")
    @Log(title = "报废审核管理", businessType = BusinessType.DELETE)
    @PostMapping("/review")
    @ResponseBody
    public AjaxResult review(String ids,String status, String rejectedReason)
    {
        try
        {
            return toAjax(kfToolsScrapApplyService.reviewByPrimary(ids,status,rejectedReason,ShiroUtils.getLoginName()));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }
    
    /**
     * 
     * @Description 查看详情
     * @CreateTime 2019年4月8日 上午9:42:17
     * @CreateBy 林龙
     * @param id
     * @param mmap
     * @return
     */
//    @RequiresPermissions("toolsScrap:scrapReview:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        mmap.put("kfToolsScrapApply", kfToolsScrapApplyService.selectByPrimaryKey(id));
        return prefix + "/scrapReview_detail";
    }
}